/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sellcar;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 *
 * @author Fabio Valenzuela
 */
public class Pedidos_VeiculoDAO {
    
    private Connection connection;
    
    public Pedidos_VeiculoDAO(){

        this.connection = new ConnectionFactory().getConnection();
        
    }
    public void adiciona (Veiculo veiculo){
        
        String sql = "insert into tb_cadastro_pedido_cotacao" + "(COD_CARRO,NOME,TELEFONE,CPF,ENDERECO,DT_NASC,TIPO"
    
        try{
            PreparedStatement stmt = connection.prepareStatement(sql);
            
            stmt.setString(1, veiculo.getPlaca());
            stmt.setString(2, veiculo.getCodCliente());
            stmt.setBigDecimal(3, veiculo.getValorVeiculo());
            stmt.setBigDecimal(4, veiculo.getEntrada());
            stmt.setBigDecimal(5, veiculo.getParcelado());
            
            
            
            stmt.execute();
            stmt.close();
            connection.close();
        }catch(SQLException e ){
            throw new RuntimeException(e);
                } 
    }
    
    
    public ResultSet atualizar_veiculo() throws SQLException {
        Connection conn = new ConnectionFactory().getConnection();
        ResultSet rsveiculo = null;
        PreparedStatement ps = null;
        try {
            String sql = "SELECT * FROM tb_cadastro_veiculos";
            ps = conn.prepareStatement(sql);
            rsveiculo = ps.executeQuery();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Ocorreu um erro no processo " + e);
        } finally {
            return rsveiculo;
        }
    }
    
    
    
}
